<?php 
if(!defined('IN_SONG')) exit('No direct script access allowed');  
/**
 * Class widget
 * 
 * @package         Kernel
 * @subpackage      Widget
 * @version         0.1
 * @copyright       Song (c) 2011
 */  
class Widget
{
    function __construct(){
        
    }
    
    public function load($name = null, $arrObj = array())
    {
        if($name == null){
            return;    
        }
        require_once WIDGET.DS.$name.'.php';
        $name = self::nameClass($name);
        $classWidget = $name.'_Widget';
        unset($name);
        $objWidget = new $classWidget($arrObj);
        unset($arrObj);
        return $objWidget->draw(); 
    }
    
    protected static function nameClass($name='')
    {
        if(!substr_count($name, '_')){
            return ucfirst(strtolower($name));
        }
        $arr = explode('_', $name);
        $result = '';
        for($i=0;$i<sizeof($arr);$i++){
            if($arr[$i]){
                $result .= ucfirst(strtolower($arr[$i]));   
            }
        }
        unset($arr);
        unset($name);
        return $result;  
    }
}
?>
